# -*- coding: utf-8 -*-
# filename: reply.py
import time
from pydantic import BaseModel

class Msg(BaseModel):
    def send(self):
        return "success"

class TextMsg(Msg):
    ToUserName: str
    FromUserName: str
    CreateTime: int
    Content: str

    def __init__(self, to_user_name, from_user_name, content):
        super().__init__(
            ToUserName=to_user_name,
            FromUserName=from_user_name,
            CreateTime=int(time.time()),
            Content=content
        )

    def send(self):
        XmlForm = """
            <xml>
                <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
                <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
                <CreateTime>{CreateTime}</CreateTime>
                <MsgType><![CDATA[text]]></MsgType>
                <Content><![CDATA[{Content}]]></Content>
            </xml>
            """

        return XmlForm.format(**self.dict())

class ImageMsg(Msg):
    ToUserName: str
    FromUserName: str
    CreateTime: int
    MediaId: str

    def __init__(self, to_user_name, from_user_name, media_id):
        super().__init__(
            ToUserName=to_user_name,
            FromUserName=from_user_name,
            CreateTime=int(time.time()),
            MediaId=media_id
        )

    def send(self):
        XmlForm = """
            <xml>
                <ToUserName><![CDATA[{ToUserName}]]></ToUserName>
                <FromUserName><![CDATA[{FromUserName}]]></FromUserName>
                <CreateTime>{CreateTime}</CreateTime>
                <MsgType><![CDATA[image]]></MsgType>
                <Image>
                <MediaId><![CDATA[{MediaId}]]></MediaId>
                </Image>
            </xml>
            """
        return XmlForm.format(**self.dict())